<?php

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;

class Test extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('test');
        // 设置参数
    }

    protected function execute(Input $input, Output $output)
    {
        $serv = new \swoole_server("0.0.0.0",9502);
        print_r($serv);
        $serv->on("WorkerStart",function ($serv,$woker_id){
            if ($woker_id == 0){
                //每隔1000ms触发一次
                swoole_timer_tick(1000, function ($timer_id,$output) {
                    //写入数据操作
                    \think\Db::name('test')->insert(['content'=>rand(100,999)]);
                    $output->writeln('test');
                });
            }
        });

        $serv->on("receive",function ($serv,$fd,$from_id,$data){
            $serv->send($fd,"Server:".$data);
        });

        $serv->start();
    	// 指令输出
    }
}
